package com.boxuegu.guanweihua25.databinding;

import android.databinding.DataBindingUtil;
import android.databinding.ObservableField;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.boxuegu.guanweihua25.databinding.databinding.ActivityMainBinding;
import com.boxuegu.guanweihua25.databinding.model.NewPerson;
import com.boxuegu.guanweihua25.databinding.model.Person;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
ActivityMainBinding binding= DataBindingUtil.setContentView(this,R.layout.activity_main);

//        setContentView(R.layout.activity_main);

        final Person person=new Person();//消除view的操作
        person.setName("csmz");
       person.setAge("20");
//      binding.setPerson1(person);

        binding.setVariable(com.boxuegu.guanweihua25.databinding.BR.person1,person);//与上一句代码作用相同

        final ObservableField<String> string =new ObservableField<>();
        string.set("username");
        binding.setVariable(com.boxuegu.guanweihua25.databinding.BR.username,string);

        final NewPerson newPerson=new NewPerson();
        newPerson.name.set("newperson name的值");
        newPerson.age.set("newperson age的值");
        binding.setVariable(com.boxuegu.guanweihua25.databinding.BR.newperson,newPerson);
        binding.setVariable(com.boxuegu.guanweihua25.databinding.BR.myclick,new MyClick());//方法绑定
//
//        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                person.setName("新设的name");
//                person.setAge("新设的age");
//                string.set("new username");
//                newPerson.name.set("newperson name的新值");
//                newPerson.age.set("newperson age的新值");
//
//
//            }
//        });


    }
    public  class MyClick{
        public void myclick1(View view){
            Log.i("MainActivity","myclick");

        }
    }
}
